<template>
    <view class="order_container">
        <view class="order_item" v-for="(item,index) in orderList" :key="index" v-if="orderList.length!=0">
            <view class="order_top_block">
                <image src="../../static/qianbao.png" class="order_top_icon"></image>
                <text>：{{item.order_amount}}元</text>
            </view>
            <view class="order_info_block">
                <view class="order_info_item">
                    <text class="order_info_item_title">订单号</text>
                    <text class="order_info_item_value">{{item.order_number}}</text>
                </view>
                <view class="order_info_item">
                    <text class="order_info_item_title">租借地点</text>
                    <text class="order_info_item_value">{{item.shop_name}}</text>
                </view>
                <view class="order_info_item">
                    <text class="order_info_item_title">开始时间</text>
                    <text class="order_info_item_value">{{item.time}}</text>
                </view>
                <view class="order_info_item">
                    <text class="order_info_item_title">结束时间</text>
                    <text class="order_info_item_value">{{item.end_time||'使用中'}}</text>
                </view>
                <view class="order_info_item">
                    <text class="order_info_item_title">电池ID</text>
                    <text class="order_info_item_value">{{item.machine_id}}</text>
                </view>
            </view>
            <view class="order_bottom_block">
                <block v-if="item.ispay==1">
                    <image src="../../static/huan.png" class="order_bottom_icon"></image>
                    <text class="order_bottom_text">已归还</text>
                </block>
                <block v-if="item.ispay==0">
                    <image src="../../static/shiyong.png" class="order_bottom_icon"></image>
                    <text class="order_bottom_text">使用中</text>
                </block>
            </view>
        </view>
    </view>
</template>

<script>

export default {
  data() {
    return {
      setting: null,
      params:{},
      orderList:[],
      /* 全部参数 */
      params: {
        pages: 1,
      },
      listPage: {
        page: 1,
        pageSize: 0,
        totalSize: 0,
        curpage: 1
      },
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.getData(that.params);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.listPage.pages = 1;
    this.params.pages = 1;
    this.getData(this.params, 2);
    uni.showNavigationBarLoading();
    uni.hideNavigationBarLoading(); //完成停止加载
    
    uni.stopPullDownRefresh(); //停止下拉刷新
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      var that = this;
      
      if (that.listPage.totalSize > that.listPage.curPage * that.listPage.pageSize) {
        that.listPage.pages++;
        that.params.pages++;
        this.getData(this.params);
      }
  },
  methods: {
    /* 获取数据 */
    getData: function (param) {
      let params=Object.assign({},param,{openid:getApp().globalData.openid}) 
      var customIndex = getApp().globalData.AddClientUrl("/order/wx_get_order",params);
      getApp().globalData.showToastLoading('loading', true);
      var that = this;
      uni.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          uni.hideLoading();
          console.log(res.data);
          that.listPage.pageSize = res.data.pageSize;
          that.listPage.curPage = res.data.curPage;
          that.listPage.totalSize = res.data.totalSize;
          that.orderList=res.data.data
          uni.hideLoading();
        },
        fail: function (res) {
          console.log("fail");
          uni.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>